#include <QCoreApplication>
#include <QSqlDatabase>
#include <QtSql>
#include <QDebug>
#include <iostream>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

    db.setHostName("127.0.0.1:3309");
    db.setDatabaseName("test");
    db.setUserName("root");
    db.setPassword("root");
    if(db.open())
    {
        qDebug()<<"database is open";
    }else{
        qDebug()<<"build error";
    }

    QSqlQuery query("select * from test");

    while(query.next())
    {
        int id = query.value("id").toInt();
        QString title = query.value("name").toString();
        std::cerr <<qPrintable(title)<<":"<<id<<std::endl;
    }

    return a.exec();
}
